using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class QnAInfo
    {
		#region Local Variable
		public enum Field
		{
			ID,
			Question,
			Answer,
			IDUserPost,
			ToEmail,
			Type,
			AnswerTime,
			CreateTime,
			Notes,
			Status
		}
		private Int64 _ID;
		private String _Question;
		private String _Answer;
		private Int64 _IDUserPost;
		private String _ToEmail;
		private String _Type;
		private DateTime _AnswerTime;
		private DateTime _CreateTime;
		private String _Notes;
		private String _Status;
		
		public Int64 ID{	get{ return _ID;} set{_ID = value;} }
		public String Question{	get{ return _Question;} set{_Question = value;} }
		public String Answer{	get{ return _Answer;} set{_Answer = value;} }
		public Int64 IDUserPost{	get{ return _IDUserPost;} set{_IDUserPost = value;} }
		public String ToEmail{	get{ return _ToEmail;} set{_ToEmail = value;} }
		public String Type{	get{ return _Type;} set{_Type = value;} }
		public DateTime AnswerTime{	get{ return _AnswerTime;} set{_AnswerTime = value;} }
		public DateTime CreateTime{	get{ return _CreateTime;} set{_CreateTime = value;} }
		public String Notes{	get{ return _Notes;} set{_Notes = value;} }
		public String Status{	get{ return _Status;} set{_Status = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public QnAInfo()
		{
			_ID = 0;
			_Question = "";
			_Answer = "";
			_IDUserPost = 0;
			_ToEmail = "";
			_Type = "";
			_AnswerTime = DateTime.Now;
			_CreateTime = DateTime.Now;
			_Notes = "";
			_Status = "";
		}
		public QnAInfo(
		Int64 ID,
		String Question,
		String Answer,
		Int64 IDUserPost,
		String ToEmail,
		String Type,
		DateTime AnswerTime,
		DateTime CreateTime,
		String Notes,
		String Status
		)
		{
			_ID = ID;
			_Question = Question;
			_Answer = Answer;
			_IDUserPost = IDUserPost;
			_ToEmail = ToEmail;
			_Type = Type;
			_AnswerTime = AnswerTime;
			_CreateTime = CreateTime;
			_Notes = Notes;
			_Status = Status;
		}
		public QnAInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt64(dr[Field.ID.ToString()]);
				_Question = dr[Field.Question.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Question.ToString()]);
				_Answer = dr[Field.Answer.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Answer.ToString()]);
				_IDUserPost = dr[Field.IDUserPost.ToString()] == DBNull.Value?0:Convert.ToInt64(dr[Field.IDUserPost.ToString()]);
				_ToEmail = dr[Field.ToEmail.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.ToEmail.ToString()]);
				_Type = dr[Field.Type.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Type.ToString()]);
				_AnswerTime = dr[Field.AnswerTime.ToString()] == DBNull.Value?DateTime.Now:Convert.ToDateTime(dr[Field.AnswerTime.ToString()]);
				_CreateTime = dr[Field.CreateTime.ToString()] == DBNull.Value?DateTime.Now:Convert.ToDateTime(dr[Field.CreateTime.ToString()]);
				_Notes = dr[Field.Notes.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Notes.ToString()]);
				_Status = dr[Field.Status.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Status.ToString()]);
			}
		}
		public QnAInfo(QnAInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_Question = objEntr.Question;			
			_Answer = objEntr.Answer;			
			_IDUserPost = objEntr.IDUserPost;			
			_ToEmail = objEntr.ToEmail;			
			_Type = objEntr.Type;			
			_AnswerTime = objEntr.AnswerTime;			
			_CreateTime = objEntr.CreateTime;			
			_Notes = objEntr.Notes;			
			_Status = objEntr.Status;			
		}
        #endregion Constructor
        
        #region InitTable
		public DataTable ToDataTable()
		{
			DataTable dt = new DataTable("QnA");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int64)),
				new DataColumn(Field.Question.ToString(), typeof(String)),
				new DataColumn(Field.Answer.ToString(), typeof(String)),
				new DataColumn(Field.IDUserPost.ToString(), typeof(Int64)),
				new DataColumn(Field.ToEmail.ToString(), typeof(String)),
				new DataColumn(Field.Type.ToString(), typeof(String)),
				new DataColumn(Field.AnswerTime.ToString(), typeof(DateTime)),
				new DataColumn(Field.CreateTime.ToString(), typeof(DateTime)),
				new DataColumn(Field.Notes.ToString(), typeof(String)),
				new DataColumn(Field.Status.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.Question.ToString()] = _Question;
			row[Field.Answer.ToString()] = _Answer;
			row[Field.IDUserPost.ToString()] = _IDUserPost;
			row[Field.ToEmail.ToString()] = _ToEmail;
			row[Field.Type.ToString()] = _Type;
			row[Field.AnswerTime.ToString()] = _AnswerTime;
			row[Field.CreateTime.ToString()] = _CreateTime;
			row[Field.Notes.ToString()] = _Notes;
			row[Field.Status.ToString()] = _Status;
			return row;
		}
        #endregion InitTable
    }
}
